Skip to content

Add Async RedisCluster #2099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
May 8, 2022
Merged

Add Async RedisCluster #2099

merged 27 commits into from
May 8, 2022

Conversation

utkarshgupta137
Copy link
Contributor

@utkarshgupta137 utkarshgupta137 commented Apr 9, 2022

Pull Request check-list

  • Does $ tox pass with this change (including linting)?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?
  • Was the change added to CHANGES file?

Description of change

Add Async Redis Cluster Client

@codecov-commenter
Copy link

codecov-commenter commented Apr 9, 2022

Codecov Report

Merging #2099 (9b1c983) into master (eca7075) will increase coverage by 0.17%.
The diff coverage is 94.86%.

@@            Coverage Diff             @@
##           master    #2099      +/-   ##
==========================================
+ Coverage   92.48%   92.66%   +0.17%     
==========================================
  Files         105      108       +3     
  Lines       25197    27174    +1977     
==========================================
+ Hits        23304    25180    +1876     
- Misses       1893     1994     +101     
Impacted Files Coverage Δ
redis/commands/parser.py 88.23% <ø> (-0.18%) ⬇️
tests/test_asyncio/test_connection.py 97.36% <ø> (-0.14%) ⬇️
tests/test_asyncio/test_retry.py 100.00% <ø> (ø)
whitelist.py 0.00% <0.00%> (ø)
redis/typing.py 86.11% <57.14%> (-4.22%) ⬇️
redis/asyncio/parser.py 80.00% <80.00%> (ø)
redis/asyncio/connection.py 84.00% <84.90%> (-0.83%) ⬇️
redis/asyncio/cluster.py 89.08% <89.08%> (ø)
tests/test_asyncio/conftest.py 93.38% <92.85%> (-1.06%) ⬇️
redis/commands/cluster.py 94.68% <96.39%> (+1.10%) ⬆️
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eca7075...9b1c983. Read the comment docs.

@chayim
Copy link
Contributor

chayim commented Apr 10, 2022

@utkarshgupta137 This looks like a great PR in progress. Just checking if you meant for it to be draft.
CC: @dvora-h

@utkarshgupta137
Copy link
Contributor Author

@utkarshgupta137 This looks like a great PR in progress. Just checking if you meant for it to be draft. CC: @dvora-h

Yeah. I've not modified any documentation or added tests and I've only done basic testing.

@utkarshgupta137 utkarshgupta137 force-pushed the master branch 7 times, most recently from 23cc596 to ea79c95 Compare April 10, 2022 23:13
@utkarshgupta137
Copy link
Contributor Author

utkarshgupta137 commented Apr 10, 2022

@chayim @dvora-h @Andrew-Chen-Wan @Grokzen

I've got all the tests running, but there are some warnings that may need to be addressed.

I've divided the PR into 3 commits:

  • The first one simply duplicates all sync code in async locations. Also copies all mark.onlynoncluster from sync test_commands to asyncio test_commands
  • Second just changes all redis client calls in async cluster tests to async/await calls
  • Third one is where all the actual changes I've made in async cluster client & test modifications required to get it working.

@utkarshgupta137 utkarshgupta137 marked this pull request as ready for review April 10, 2022 23:15
@chayim
Copy link
Contributor

chayim commented Apr 11, 2022

@dvora-h Can you give @utkarshgupta137 a hand with this? How about integrating the documentation side - adding cluster examples, etc.

@utkarshgupta137 What else can we do to help? The last piece I see is the test_acl_log failure, at least from a starting position.

@utkarshgupta137
Copy link
Contributor Author

utkarshgupta137 commented Apr 11, 2022

@dvora-h Can you give @utkarshgupta137 a hand with this? How about integrating the documentation side - adding cluster examples, etc.

@utkarshgupta137 What else can we do to help? The last piece I see is the test_acl_log failure, at least from a starting position.

That test is only failing on 3.6. If you see the cancelled 3.7+ tests, it hasn't failed in that case. Also ran normally on my amd64 mac py3.9.

The failure seems to be related to client closing. There are also warnings about the client not closing properly from other tests. Both of the problems are probably related. If anyone could verify the close() as well as the initialize() logic, that would be great.

@utkarshgupta137
Copy link
Contributor Author

utkarshgupta137 commented Apr 11, 2022

Looks like the tests are failing on 3.6 due to related issue aio-libs-abandoned/aioredis-py#1273.

Copy link
Contributor

@Andrew-Chen-Wang Andrew-Chen-Wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just an initial read through. This looks great!

@Andrew-Chen-Wang
Copy link
Contributor

Andrew-Chen-Wang commented Apr 14, 2022 via email

@utkarshgupta137
Copy link
Contributor Author

@chayim @Andrew-Chen-Wang Most of the warnings have been resolved. The test_acl_log is still failing on 3.6, I'll check it tomorrow.

@Andrew-Chen-Wang
Copy link
Contributor

@chayim when are we dropping Python 3.6? Or start marking it as unneeded for merging.

@utkarshgupta137
Copy link
Contributor Author

utkarshgupta137 commented Apr 15, 2022

test_acl_log is fixed now. It was failing because I had an empty yield statement in async def.

@utkarshgupta137 utkarshgupta137 force-pushed the master branch 3 times, most recently from 640e9ec to 7537178 Compare April 16, 2022 00:20
@chayim
Copy link
Contributor

chayim commented Apr 17, 2022

@utkarshgupta137 Dropping python 3.6 support isn't a 4.2 thing, but could happen as we start to clean up the repo in 4.3+/5.x. There's a lot of 3.6 out there - even if I'd love to be 3.7+.

@@ -41,6 +42,10 @@
autosectionlabel_prefix_document = True
autosectionlabel_maxdepth = 2

# AutodocTypehints settings.
always_document_param_types = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Had no idea this was an option.

Copy link
Contributor

@chayim chayim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@utkarshgupta137 This is really, really close. I added tiny comments - that to be honest, I'm okay with eliminating. Also, it works nicely :).

I think we can get this in a 4.3.0 release, immediately - as this necessitates a minor version bump. WDYT?

@utkarshgupta137 utkarshgupta137 force-pushed the master branch 3 times, most recently from 82abb20 to 9f8e57a Compare April 27, 2022 10:58
@utkarshgupta137 utkarshgupta137 requested a review from chayim April 27, 2022 10:58
@utkarshgupta137
Copy link
Contributor Author

@chayim Can you hold off on merging this? I think making it thread-safe is trivial.

@chayim
Copy link
Contributor

chayim commented Apr 27, 2022

Of course - but beware of scope creep.

@utkarshgupta137
Copy link
Contributor Author

utkarshgupta137 commented Apr 27, 2022

@chayim According to https://docs.python.org/3/library/asyncio-dev.html#asyncio-multithreading, asyncio is not meant to be used with threading anyway, so I've removed the threading related checks & added a test for asyncio.gather

@Grokzen
Copy link

Grokzen commented Apr 27, 2022

@utkarshgupta137 I am no longer part of working with redis clients here or in my own repo any longer. I have handed the future of cluster related things to this repo so there won't be any need for me to review or be a part of any cluster related development :)

The major good part of this PR is that you get asyncio into here, the major pain going forward tho will be that it seems you have to clone and duplicate the normal code and asyncio code =( I am sure maintaining that is going to be a much bigger job after this get in.

Is the plan to require any future modifications and contributions to make both normal and asyncio code compatible with any change? or will it be more on a "lets hope it will happen" basis?

@utkarshgupta137
Copy link
Contributor Author

@Grokzen I will carry over all the changes/optimisations I've made to async to the sync client soon. For the long term, there is a discussion in #2119 regarding moving to sansio approach. It is IMO a much better approach for supporting both sync/async & I can port the cluster code to it if we go with it.

@chayim
Copy link
Contributor

chayim commented Apr 28, 2022

@chayim According to docs.python.org/3/library/asyncio-dev.html#asyncio-multithreading, asyncio is not meant to be used with threading anyway, so I've removed the threading related checks & added a test for asyncio.gather

I mean I use async and threading all the time - even if I shouldn't. But, never in prod. I think we're ready to merge this. @dvora-h ready for the new version when you are.

@chayim
Copy link
Contributor

chayim commented May 2, 2022

@utkarshgupta137 I just merged master in. We're very, very close!

@chayim chayim added the feature New feature label May 2, 2022
@dvora-h dvora-h merged commit 061d97a into redis:master May 8, 2022
@Andrew-Chen-Wang
Copy link
Contributor

Andrew-Chen-Wang commented May 10, 2022

this looks great. thanks @utkarshgupta137 !!!!

@karwinliu
Copy link

Does this support pipeline by any chance?

@utkarshgupta137
Copy link
Contributor Author

Does this support pipeline by any chance?

Not at the moment. I just wanted to add basic support first and see if there are any issues. I will try to add pipeline support as well as a few other missing features like locks, pubsub, monitor etc.

@karwinliu
Copy link

karwinliu commented May 18, 2022

Thanks @utkarshgupta137. What you have done on the async support is really helpful! Our project relies heavily on pipelines, so I wonder if there's any rough timeline you have in mind for these supports, or if there's any workaround for the time-being.

@utkarshgupta137
Copy link
Contributor Author

Thanks @utkarshgupta137. What you have done on the async support is really helpful! Our project relies heavily on pipelines, so I wonder if there's any rough timeline you have in mind for these supports, or if there's any workaround for the time-being.

I've been considering switching to pipelines as well. But between me writing the code, tests, review, & release, it may take 2-3 weeks. In the meantime, I think there are a couple of other packages with async cluster like aredis which may've support for it, but I'm not sure.

@akx
Copy link
Contributor

akx commented Sep 19, 2022

Oof, there's a lot of copy-paste in this PR... My PyCharm's Locate Duplicates is just lighting up :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants